package top.aicats.blog.BlogManage.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import top.aicats.blog.BlogManage.mapper.BlogContentMapper;
import top.aicats.blog.BlogManage.model.BlogContent;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

/**
 * @author sjc
 * @version 1.0
 * @date 2020/1/11 15:42
 * @email 952491025@qq.com
 */
@Service
public class BlogContentImpl implements IBlogContentService {

    @Autowired
    BlogContentMapper blogContentMapper;

    @Override
    public Integer insertOneBlog(BlogContent content) {
        content.setBlogContentRefid(UUID.randomUUID().toString().replaceAll("-", ""));
        content.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return blogContentMapper.insertOneBlog(content);
    }

    @Override
    public List<BlogContent> getAllBlogTitleBySubRefid(BlogContent content) {
        return blogContentMapper.getAllBlogTitleBySubTypeRefid(content);
    }

    @Override
    public List<BlogContent> getBlogContentByRefid(BlogContent content) {
        return blogContentMapper.getAllBlogContentBySubTypeRefid(content);
    }

    @Override
    public List<BlogContent> getBlogTitleInfoByPaging(Integer pageSize,  Integer page,  String sortField,  Boolean desc) {
        Integer startPage = pageSize * (page -1);
        return blogContentMapper.getBlogTitleInfoByPaging(startPage, pageSize, sortField, desc);
    }
}
